/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.dao.professor;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import edu.uwm.universitydb.framework.transactional.db.command.impl.TransactionalDataManipulationCommandBase;
import edu.uwm.universitydb.model.Professor;

/**
 * <code>InsertProfessorCommand</type>
 * Command class to insert a record to table professor
 * 
 * @author Shyam Nair
 */
public class InsertProfessorCommand extends TransactionalDataManipulationCommandBase
{

    /** SQL query for performing insert */
    private static final String SQL = "insert into university.professor (prof_ssn, name, age, rank, research_speciality) values (?,?,?,?,?);";

    /** attribute holding the professor entry to be inserted */
    private final Professor mProfessor;
    
    /**
     * 
     * @param professor
     */
    public InsertProfessorCommand(final Professor professor)
    {
        mProfessor = professor;
    }
    
    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return SQL;
    }
    

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(PreparedStatement pStmt) throws SQLException
    {
        // set ssn
        final String ssn = mProfessor.getSsnNum();
        pStmt.setString(1, ssn);
        // set name
        final String name = mProfessor.getName();
        pStmt.setString(2, name);
        // age
        final int age = mProfessor.getAge();
        pStmt.setInt(3, age);
        // rank
        final String rank = mProfessor.getRank();
        pStmt.setString(4, rank);
        // researchSpeciality
        final String researchSpeciality = mProfessor.getResearchSpeciality();
        pStmt.setString(5, researchSpeciality);
    }

}
/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 19, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */